<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="短剧唯一标识" prop="dramaId">
        <el-input
          v-model="queryParams.dramaId"
          placeholder="请输入短剧唯一标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="短剧标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入短剧标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="题材标签" prop="tags">
        <el-input
          v-model="queryParams.tags"
          placeholder="请输入题材标签，如:都市、言情"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主要演员" prop="mainActors">
        <el-input
          v-model="queryParams.mainActors"
          placeholder="请输入主要演员"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="总集数" prop="totalEpisodes">
        <el-input
          v-model="queryParams.totalEpisodes"
          placeholder="请输入总集数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="发布平台" prop="platform">
        <el-input
          v-model="queryParams.platform"
          placeholder="请输入发布平台"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="上线日期" prop="releaseDate">
        <el-date-picker clearable
          v-model="queryParams.releaseDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择上线日期">
        </el-date-picker>
      </el-form-item>-->
<!--      <el-form-item label="总播放量" prop="totalPlayCount">
        <el-input
          v-model="queryParams.totalPlayCount"
          placeholder="请输入总播放量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总点赞数" prop="totalLikeCount">
        <el-input
          v-model="queryParams.totalLikeCount"
          placeholder="请输入总点赞数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总评论数" prop="totalCommentCount">
        <el-input
          v-model="queryParams.totalCommentCount"
          placeholder="请输入总评论数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总收藏数" prop="totalCollectCount">
        <el-input
          v-model="queryParams.totalCollectCount"
          placeholder="请输入总收藏数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="完播率" prop="completionRate">
        <el-input
          v-model="queryParams.completionRate"
          placeholder="请输入完播率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="热度评分" prop="hotScore">
        <el-input
          v-model="queryParams.hotScore"
          placeholder="请输入热度评分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="互动率" prop="interactionRate">
        <el-input
          v-model="queryParams.interactionRate"
          placeholder="请输入互动率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有详细演员信息" prop="hasDetailedInfo">
        <el-input
          v-model="queryParams.hasDetailedInfo"
          placeholder="请输入是否有详细演员信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有真实播放量" prop="hasRealPlayCount">
        <el-input
          v-model="queryParams.hasRealPlayCount"
          placeholder="请输入是否有真实播放量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="匹配标签数量" prop="matchCount">
        <el-input
          v-model="queryParams.matchCount"
          placeholder="请输入匹配标签数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据来源" prop="source">
        <el-input
          v-model="queryParams.source"
          placeholder="请输入数据来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>--><!--
      <el-form-item label="${comment}" prop="createdAt">
        <el-date-picker clearable
          v-model="queryParams.createdAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="updatedAt">
        <el-date-picker clearable
          v-model="queryParams.updatedAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:dramas:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:dramas:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:dramas:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:dramas:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="dramasList">
      <!-- 按照你要求的顺序排列 -->
      <el-table-column label="短剧唯一标识" align="center" prop="dramaId" width="120" />
      <el-table-column label="短剧标题" align="center" prop="title" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="封面URL" align="center" prop="coverImage" width="120" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.coverImage"
            style="width: 50px; height: 50px"
            :src="scope.row.coverImage"
            :preview-src-list="[scope.row.coverImage]"
            fit="cover"
          />
          <span v-else>无封面</span>
        </template>
      </el-table-column>
      <el-table-column label="题材标签" align="center" prop="tags" width="120" :show-overflow-tooltip="true" />
      <el-table-column label="主要演员" align="center" prop="mainActors" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标题链接" align="center" prop="titleLink" width="120" :show-overflow-tooltip="true" />
      <el-table-column label="剧情简介" align="center" prop="description" width="200" :show-overflow-tooltip="true" />
      <el-table-column label="发布平台" align="center" prop="platform" width="100" />
      <el-table-column label="总集数" align="center" prop="totalEpisodes" width="80" />
      <el-table-column label="上线日期" align="center" prop="releaseDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.releaseDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总播放量" align="center" prop="totalPlayCount" width="100" />
      <el-table-column label="总点赞数" align="center" prop="totalLikeCount" width="100" />
      <el-table-column label="总评论数" align="center" prop="totalCommentCount" width="100" />
      <el-table-column label="总收藏数" align="center" prop="totalCollectCount" width="100" />
      <el-table-column label="完播率" align="center" prop="completionRate" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.completionRate">{{ (scope.row.completionRate * 100).toFixed(1) }}%</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="热度评分" align="center" prop="hotScore" width="100" />
      <el-table-column label="互动率" align="center" prop="interactionRate" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.interactionRate">{{ (scope.row.interactionRate * 100).toFixed(2) }}%</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="简介关键词" align="center" prop="descriptionKeywords" width="120" :show-overflow-tooltip="true" />

      <!-- 操作列保持不变 -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            link
            type="primary"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:dramas:edit']"
          >修改</el-button>
          <el-button
            link
            type="primary"
            icon="Delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dramas:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改短剧基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="短剧唯一标识" prop="dramaId">
          <el-input v-model="form.dramaId" placeholder="请输入短剧唯一标识" />
        </el-form-item>
        <el-form-item label="短剧标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入短剧标题" />
        </el-form-item>
        <el-form-item label="题材标签" prop="tags">
          <el-input v-model="form.tags" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="主要演员" prop="mainActors">
          <el-input v-model="form.mainActors" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="剧情简介" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="总集数" prop="totalEpisodes">
          <el-input v-model="form.totalEpisodes" placeholder="请输入总集数" />
        </el-form-item>
        <el-form-item label="发布平台" prop="platform">
          <el-input v-model="form.platform" placeholder="请输入发布平台" />
        </el-form-item>
        <el-form-item label="上线日期" prop="releaseDate">
          <el-date-picker clearable
            v-model="form.releaseDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上线日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总播放量" prop="totalPlayCount">
          <el-input v-model="form.totalPlayCount" placeholder="请输入总播放量" />
        </el-form-item>
        <el-form-item label="总点赞数" prop="totalLikeCount">
          <el-input v-model="form.totalLikeCount" placeholder="请输入总点赞数" />
        </el-form-item>
        <el-form-item label="总评论数" prop="totalCommentCount">
          <el-input v-model="form.totalCommentCount" placeholder="请输入总评论数" />
        </el-form-item>
        <el-form-item label="总收藏数" prop="totalCollectCount">
          <el-input v-model="form.totalCollectCount" placeholder="请输入总收藏数" />
        </el-form-item>
        <el-form-item label="完播率" prop="completionRate">
          <el-input v-model="form.completionRate" placeholder="请输入完播率" />
        </el-form-item>
        <el-form-item label="热度评分" prop="hotScore">
          <el-input v-model="form.hotScore" placeholder="请输入热度评分" />
        </el-form-item>
        <el-form-item label="互动率" prop="interactionRate">
          <el-input v-model="form.interactionRate" placeholder="请输入互动率" />
        </el-form-item>
        <el-form-item label="封面图URL" prop="coverImage">
          <image-upload v-model="form.coverImage"/>
        </el-form-item>
        <el-form-item label="标题链接" prop="titleLink">
          <el-input v-model="form.titleLink" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="简介关键词" prop="descriptionKeywords">
          <el-input v-model="form.descriptionKeywords" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否有详细演员信息" prop="hasDetailedInfo">
          <el-input v-model="form.hasDetailedInfo" placeholder="请输入是否有详细演员信息" />
        </el-form-item>
        <el-form-item label="是否有真实播放量" prop="hasRealPlayCount">
          <el-input v-model="form.hasRealPlayCount" placeholder="请输入是否有真实播放量" />
        </el-form-item>
        <el-form-item label="匹配的标签" prop="matchedTags">
          <el-input v-model="form.matchedTags" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="匹配标签数量" prop="matchCount">
          <el-input v-model="form.matchCount" placeholder="请输入匹配标签数量" />
        </el-form-item>
        <el-form-item label="数据来源" prop="source">
          <el-input v-model="form.source" placeholder="请输入数据来源" />
        </el-form-item>
        <el-form-item label="${comment}" prop="createdAt">
          <el-date-picker clearable
            v-model="form.createdAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="updatedAt">
          <el-date-picker clearable
            v-model="form.updatedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDramas, getDramas, delDramas, addDramas, updateDramas } from "@/api/system/dramas"

export default {
  name: "Dramas",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 短剧基础信息表格数据
      dramasList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dramaId: null,
        title: null,
        tags: null,
        mainActors: null,
        // description: null,
        // totalEpisodes: null,
        platform: null,
        // releaseDate: null,
        // totalPlayCount: null,
        // totalLikeCount: null,
        // totalCommentCount: null,
        // totalCollectCount: null,
        // completionRate: null,
        // hotScore: null,
        // interactionRate: null,
        // coverImage: null,
        // titleLink: null,
        // descriptionKeywords: null,
        // dataQuality: null,
        // hasDetailedInfo: null,
        // hasRealPlayCount: null,
        // preciseFeatureVector: null,
        // matchedTags: null,
        // matchCount: null,
        // source: null,
        // createdAt: null,
        // updatedAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        dramaId: [
          { required: true, message: "短剧唯一标识不能为空", trigger: "blur" }
        ],
        title: [
          { required: true, message: "短剧标题不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询短剧基础信息列表 */
    getList() {
      this.loading = true
      listDramas(this.queryParams).then(response => {
        this.dramasList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dramaId: null,
        title: null,
        tags: null,
        mainActors: null,
        description: null,
        totalEpisodes: null,
        platform: null,
        releaseDate: null,
        totalPlayCount: null,
        totalLikeCount: null,
        totalCommentCount: null,
        totalCollectCount: null,
        completionRate: null,
        hotScore: null,
        interactionRate: null,
        coverImage: null,
        titleLink: null,
        descriptionKeywords: null,
        dataQuality: null,
        hasDetailedInfo: null,
        hasRealPlayCount: null,
        preciseFeatureVector: null,
        matchedTags: null,
        matchCount: null,
        source: null,
        createdAt: null,
        updatedAt: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加短剧基础信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getDramas(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改短剧基础信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDramas(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addDramas(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除短剧基础信息编号为"' + ids + '"的数据项？').then(function() {
        return delDramas(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/dramas/export', {
        ...this.queryParams
      }, `dramas_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
